#!/usr/bin/env python3.10.6
# -*- coding: utf-8 -*-
# Author: Bobby Sheng <Bobby@sky-cloud.net>
from units.get_config_data import get_config_yaml_data
import requests
import jsonpath

Config = get_config_yaml_data()


def tenant_access_token():
    """获取引用tenant_access_token
    :return: tenant_access_token
    """
    data = {"app_id": jsonpath.jsonpath(Config, "$.feishu.app_id")[0],
            "app_secret": jsonpath.jsonpath(Config, "$.feishu.app_secret")[0]}

    res = requests.post(jsonpath.jsonpath(Config, "$.feishu.webhook_token")[0], data=data).json()
    headers = {
        'Content-Type': 'application/json',
        'Authorization': "Bearer " + res["app_access_token"]
    }
    return headers
